<?php

class RemoteController extends Controller
{
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		$this->renderFile('index.tpl');
	}

	public function actionNew()
	{
		$pics = Yii::app()->request->getParam('pics');
		try {
			$arrPic = json_decode($pics, true);
			foreach ($arrPic as $key => $item) {
				if(isset($item['pic_url'])){
					$pic = array();
					$pic['pic_url'] = $item['pic_url'];
					$pic['source'] = isset($item['source']) ? $item['source'] : 'unknown';
					$pic['pic_key'] = $item['pic_key'] ? $item['pic_key'] : $pic['source']. '_'. uniqid();
					$pic['crawl_time'] = TimeUtil::now();
					
					$modelPicture = new Picture();
					$modelPicture->save($pic);
				}
			}
		} catch(Exception $err){

		}
		
		Yii::log($pics, "info");
		echo $pics;
	}

}